package org.example.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class MessageSendController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/sendTest")
    public void sendTestMessage(@RequestParam("no") String number) {
        // send message
        this.rabbitTemplate.convertAndSend("test", "我的消息序号是：" + number);
    }

    @GetMapping("/sendOrder")
    public void sendOrderMessage() {
        Map<String, String> orderMessage = new HashMap<>();
        orderMessage.put("code", "200");
        orderMessage.put("message", "123");
        // send message
        this.rabbitTemplate.convertAndSend("order", orderMessage);
    }
}
